package msg

import (
	"fmt"
	"github.com/xuri/excelize/v2"
	"leaf/network/protobuf"
	"reflect"
	"server/pb/pb_go/proto"
)

var (
	Processor = protobuf.NewProcessor()
	Protos    = make([]interface{}, 0)
)

func init() {
	Register(&proto.C2S_Login{})
	Register(&proto.S2C_Login{})
	Submit()
}

func Register(a interface{}) {
	Protos = append(Protos, a)
}
func Submit() {
	f := excelize.NewFile()
	// 创建一个工作表
	index := f.NewSheet("Sheet1")
	for i, v := range Protos {
		Processor.Register(reflect.TypeOf(v))
		// 设置单元格的值 |name|id|
		f.SetCellValue("Sheet1", fmt.Sprintf("A%d", i+1), reflect.TypeOf(v).Elem().Name())
		f.SetCellValue("Sheet1", fmt.Sprintf("B%d", i+1), i)

	}
	// 设置工作簿的默认工作表
	f.SetActiveSheet(index)
	// 根据指定路径保存文件
	if err := f.SaveAs("proto.xlsx"); err != nil {
		fmt.Println(err)
	}
}
